<!DOCTYPE html>
<title>Computed style of the filter property</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
function assert_computed_style(property, value, expectedValue) {
  if (expectedValue === undefined)
    expectedValue = value;

  var stringifiedValue = JSON.stringify(value);

  test(function() {
    var div = document.createElement('div');
    div.style[property] = value;
    document.head.appendChild(div);
    var computedStyleValue = getComputedStyle(div)[property];
    div.remove();
    assert_equals(computedStyleValue, expectedValue);
  }, "Computed style after setting e.style['" + property + "'] = " + stringifiedValue);
}

assert_computed_style("filter", "url('#a')", 'url("#a")'); // Basic reference
assert_computed_style("filter", "url(#a)", 'url("#a")'); // Bare unquoted reference converting to quoted form
assert_computed_style("filter", "url('#a') url('#b')", 'url("#a") url("#b")'); // Multiple references

assert_computed_style("filter", "grayscale(1)"); // Integer value
assert_computed_style("filter", "grayscale(1.0)", "grayscale(1)"); // Float value converts to integer
assert_computed_style("filter", "grayscale(0)"); // Zero value
assert_computed_style("filter", "grayscale()", "grayscale(1)"); // No arguments
assert_computed_style("filter", "grayscale(0.5) grayscale(0.25)"); // Multiple values

assert_computed_style("filter", "sepia(1)"); // Integer value
assert_computed_style("filter", "sepia(1.0)", "sepia(1)"); // Float value converts to integer
assert_computed_style("filter", "sepia(0)"); // Zero value
assert_computed_style("filter", "sepia()", "sepia(1)"); // No arguments
assert_computed_style("filter", "sepia(0.5) sepia(0.25)"); // Multiple values

assert_computed_style("filter", "saturate(1)"); // Integer value
assert_computed_style("filter", "saturate(1.0)", "saturate(1)"); // Float value converts to integer
assert_computed_style("filter", "saturate(0)"); // Zero value
assert_computed_style("filter", "saturate()", "saturate(1)"); // No arguments
assert_computed_style("filter", "saturate(0.5) saturate(0.25)"); // Multiple values

assert_computed_style("filter", "hue-rotate(10deg)"); // Degrees value as integer
assert_computed_style("filter", "hue-rotate(10.0deg)", "hue-rotate(10deg)"); // Degrees float value converts to integer
assert_computed_style("filter", "hue-rotate(10rad)", "hue-rotate(572.958deg)"); // Radians value
assert_computed_style("filter", "hue-rotate(10grad)", "hue-rotate(9deg)"); // Gradians value
assert_computed_style("filter", "hue-rotate(0.5turn)", "hue-rotate(180deg)"); // Turns value
assert_computed_style("filter", "hue-rotate(0)", "hue-rotate(0deg)"); // Zero value
assert_computed_style("filter", "hue-rotate()", "hue-rotate(0deg)"); // No arguments

assert_computed_style("filter", "invert(1)"); // Integer value
assert_computed_style("filter", "invert(1.0)", "invert(1)"); // Float value converts to integer
assert_computed_style("filter", "invert(0)"); // Zero value
assert_computed_style("filter", "invert()", "invert(1)"); // No arguments
assert_computed_style("filter", "invert(0.5) invert(0.25)"); // Multiple values

assert_computed_style("filter", "opacity(1)"); // Integer value
assert_computed_style("filter", "opacity(1.0)", "opacity(1)"); // Float value converts to integer
assert_computed_style("filter", "opacity(0)"); // Zero value
assert_computed_style("filter", "opacity()", "opacity(1)"); // No arguments
assert_computed_style("filter", "opacity(0.5) opacity(0.25)"); // Multiple values

assert_computed_style("filter", "brightness(1)"); // Integer value
assert_computed_style("filter", "brightness(1.0)", "brightness(1)"); // Float value converts to integer
assert_computed_style("filter", "brightness(0)"); // Zero value
assert_computed_style("filter", "brightness()", "brightness(1)"); // No arguments
assert_computed_style("filter", "brightness(0.5) brightness(0.25)"); // Multiple values

assert_computed_style("filter", "contrast(1)"); // Integer value
assert_computed_style("filter", "contrast(2)"); // Value greater than 1
assert_computed_style("filter", "contrast(1.0)", "contrast(1)"); // Float value converts to integer
assert_computed_style("filter", "contrast(0)"); // Zero value
assert_computed_style("filter", "contrast()", "contrast(1)"); // No arguments
assert_computed_style("filter", "contrast(0.5) contrast(0.25)"); // Multiple values

assert_computed_style("filter", "blur(0)", "blur(0px)"); // One zero to px
assert_computed_style("filter", "blur(2em)", "blur(32px)"); // One length
assert_computed_style("filter", "blur(5px)"); // One length
assert_computed_style("filter", "blur()", "blur(0px)"); // No arguments

assert_computed_style("filter",
  "drop-shadow(red 1px 2px 3px)", "drop-shadow(rgb(255, 0, 0) 1px 2px 3px)"); // Color then three values
assert_computed_style("filter",
  "drop-shadow(1px 2px 3px red)", "drop-shadow(rgb(255, 0, 0) 1px 2px 3px)"); // Three values then color
assert_computed_style("filter",
  "drop-shadow(#abc 0 0 0)", "drop-shadow(rgb(170, 187, 204) 0px 0px 0px)"); // Color then three values with zero length
assert_computed_style("filter",
  "drop-shadow(0 0 0)", "drop-shadow(rgb(0, 0, 0) 0px 0px 0px)"); // Three values with zero length
assert_computed_style("filter",
  "drop-shadow(1px 2px)", "drop-shadow(rgb(0, 0, 0) 1px 2px 0px)"); // Two values no color

// Combinations
assert_computed_style("filter", "grayscale(1) url('#a')", 'grayscale(1) url("#a")');
assert_computed_style("filter", "sepia(0.5) grayscale(0.25)");
assert_computed_style("filter", "saturate(0.5) grayscale(0.25)");
assert_computed_style("filter", "hue-rotate(10deg) grayscale(0.25)");
assert_computed_style("filter", "invert(0.5) grayscale(0.25)");
assert_computed_style("filter", "opacity(0.5) grayscale(0.25)");
assert_computed_style("filter", "brightness(0.5) grayscale(0.25)");
assert_computed_style("filter", "contrast(0.5) grayscale(0.25)");
assert_computed_style("filter",
  "grayscale(0.5) sepia(0.25) saturate(0.75) hue-rotate(35deg) invert(0.2) opacity(0.9) blur(5px)");
assert_computed_style("filter",
  "grayscale(50%) sepia(25%) saturate(75%) invert(20%) opacity(90%) brightness(60%) contrast(30%)",
  "grayscale(0.5) sepia(0.25) saturate(0.75) invert(0.2) opacity(0.9) brightness(0.6) contrast(0.3)");
</script>
